package org.iteam.xlz.manager.action.customerservice;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.iteam.web.shiro.ShiroUtil;
import org.iteam.web.struts.action.AbstractModuleAction;
import org.iteam.web.struts.action.RestAction;
import org.iteam.xlz.core.entity.customerservice.CustomerService;
import org.iteam.xlz.core.service.base.ServiceTypeService;
import org.iteam.xlz.core.service.customerservice.CustomerServiceService;

@SuppressWarnings("unchecked")
@Results({@Result(name="INDEX",type="freemarker",location="/WEB-INF/content/service/service/index.html"),
		  @Result(name="EDIT",type="freemarker",location="/WEB-INF/content/service/service/edit.html")})
public class ServiceAction extends AbstractModuleAction<CustomerService> implements RestAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6865321113163782333L;
	private final String PATH="/service/service";
	@Override
	public CustomerService getModel() {
		if(null==model){
			model=new CustomerService();
		}
		return model;
	}	
	
	@Override
	@Action(PATH+"/index")
	public String index() {
		map.put("typeTree",ServiceTypeService.getInstance().getAllTree());
		return INDEX;
	}

	@Override
	@Action(PATH+"/query")
	public String query() {
		map.put("total",CustomerServiceService.getInstance().counts());
		map.put("rows",CustomerServiceService.getInstance().query(page,rows));
		return MAP;
	}

	@Override
	@Action(PATH+"/create")
	public String create() {
		model.setCreator(ShiroUtil.currentAccount());
		map.put("state",CustomerServiceService.getInstance().create(model));
		return MAP;
	}

	@Override
	@Action(PATH+"/update")
	public String update() {
		map.put("state",CustomerServiceService.getInstance().update(model));
		return MAP;
	}

	@Override
	public String delete() {
		return null;
	}

	@Override
	@Action(PATH+"/getProducts")
	public String destroy() {
		return MAP;
	}

	@Override
	@Action(PATH+"/{_id}/edit")
	public String edit() {
		map.put("typeTree",ServiceTypeService.getInstance().getAllTree());
		object=CustomerServiceService.getInstance().find(_id);
		return EDIT;
	}

	@Override
	@Action(PATH+"/new")
	public String editNew() {
		map.put("typeTree",ServiceTypeService.getInstance().getAllTree());
		return EDIT;
	}

	@Override
	public String show() {
		return null;
	}	
}
